﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Hangout.Client
{
    public static class Services
    {
        public static FacebookService.FacebookServiceClient facebookServiceClient { get; set; }
        public static AccountService.AccountServiceClient AccountServiceClient { get; set; }
        public static ExceptionReportingService.ExceptionReportingServiceClient ExceptionReportingServiceClient { get; set; }
        public static GeocodeService.GeocodeServiceClient GeocodeServiceClient { get; set; }
        public static GeoLocationSearchService.SearchServiceClient GeoLocationSearchServiceClient { get; set; }
        public static MeetupService.MeetupServiceClient MeetupServiceClient { get; set; }
        public static NotificationService.NotificationServiceClient NotificationServiceClient { get; set; }
        public static PushNotificationService.PushNotificationServiceClient PushNotificationServiceClient { get; set; }
        public static TextService.TextServiceClient TextServiceClient { get; set; }
        public static TrophyService.TrophyServiceClient TrophyServiceClient { get; set; }
        public static UserLocationService.UserLocationServiceClient UserLocationServiceClient { get; set; }
        public static UserScoreService.UserScoreServiceClient UserScoreServiceClient { get; set; }


        public static void Close()
        {
            AccountServiceClient.CloseAsync();
            ExceptionReportingServiceClient.CloseAsync();
            GeocodeServiceClient.CloseAsync();
            GeoLocationSearchServiceClient.CloseAsync();
            MeetupServiceClient.CloseAsync();
            NotificationServiceClient.CloseAsync();
            PushNotificationServiceClient.CloseAsync();
            TextServiceClient.CloseAsync();
            TrophyServiceClient.CloseAsync();
            UserLocationServiceClient.CloseAsync();
            UserScoreServiceClient.CloseAsync();
            facebookServiceClient.CloseAsync();
        }

        public static void Open()
        {
            if (AccountServiceClient == null)
            {
                AccountServiceClient = new AccountService.AccountServiceClient();
            }

            AccountServiceClient.OpenAsync();

            if (ExceptionReportingServiceClient == null)
            {
                ExceptionReportingServiceClient = new ExceptionReportingService.ExceptionReportingServiceClient();
            }

            ExceptionReportingServiceClient.OpenAsync();

            if (GeocodeServiceClient == null)
            {
                GeocodeServiceClient = new GeocodeService.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
            }

            GeocodeServiceClient.OpenAsync();

            if (GeoLocationSearchServiceClient == null)
            {
                GeoLocationSearchServiceClient = new GeoLocationSearchService.SearchServiceClient();
            }

            GeoLocationSearchServiceClient.OpenAsync();

            if (MeetupServiceClient == null)
            {
                MeetupServiceClient = new MeetupService.MeetupServiceClient();
            }
            
            MeetupServiceClient.OpenAsync();

            if (NotificationServiceClient == null)
            {
                NotificationServiceClient = new NotificationService.NotificationServiceClient();
            }
            
            NotificationServiceClient.OpenAsync();

            if (PushNotificationServiceClient == null)
            {
                PushNotificationServiceClient = new PushNotificationService.PushNotificationServiceClient();
            }

            PushNotificationServiceClient.OpenAsync();

            if (TextServiceClient == null)
            {
                TextServiceClient = new TextService.TextServiceClient();
            }
            
            TextServiceClient.OpenAsync();
            
            if(TrophyServiceClient==null)
            {
                TrophyServiceClient = new TrophyService.TrophyServiceClient();
            }
            
            TrophyServiceClient.OpenAsync();

            if (UserLocationServiceClient == null)
            {
                UserLocationServiceClient = new UserLocationService.UserLocationServiceClient();
            }
            
            UserLocationServiceClient.OpenAsync();

            if (UserScoreServiceClient == null)
            {
                UserScoreServiceClient = new UserScoreService.UserScoreServiceClient();
            }

            UserScoreServiceClient.OpenAsync();

            if (facebookServiceClient == null)
                facebookServiceClient = new FacebookService.FacebookServiceClient();

            facebookServiceClient.OpenAsync();
        }
    }
}
